
<%@page import="java.text.DecimalFormatSymbols"%>
<%@page import="java.text.NumberFormat"%>
<%@page import="java.text.DecimalFormat"%>

<%@page import="java.util.ArrayList"%>

<%@page import="br.com.sadim.hospital.Consulta"%>
<%@page import="org.hibernate.Session"%>
<%@page import="br.com.sadim.util.HibernateUtil"%>
<%@page import="org.hibernate.Transaction"%>


<%@page import="java.util.Calendar"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>

<style type="text/css">
	body {
		font-family: monospace;
		font-size: 12pt;
		font-variant: small-caps;
		margin: 0px;
		padding: 0px;
	}
	
	table.tabela {
		width: 23cm;
		border: 2px solid #000;
		margin: 10px;
	}
	
	.tabela thead td {
		color: #888;
	}
	
	.tabela_vencimentos td {
		border-right: 2px solid #000;
		text-align: center;
		padding: 2px 10px;
	}
	
	.tabela_vencimentos thead td {
		border-bottom: 2px solid #000;
	}
</style>

<script type="text/javascript">
	window.print();
</script>

</head>
<body>

<%
	Calendar data = Calendar.getInstance();
	String[] meses = {"Janeiro", "Fevereiro",
		  "Março", "Abril", "Maio", "Junho", "Julho",
		  "Agosto", "Setembro", "Outubro", "Novembro",
		  "Dezembro"};
	
	DecimalFormatSymbols df = new DecimalFormatSymbols();
	df.setDecimalSeparator(',');
	df.setGroupingSeparator('.');
	NumberFormat formatter = new DecimalFormat("###,##0.00", df);
	try {
		Session se = HibernateUtil.getSessionFactory().getCurrentSession();
		Transaction tx = se.beginTransaction();
		Consulta consulta = (Consulta) se.get(Consulta.class, Integer.parseInt(request.getParameter("id")));
		tx.commit();

%>

	<table class="tabela">
		<tr>
			<td style="width: 60%">Doctor ERP</td>
			<td style="text-align: center; font-family: sans-serif; font-size: 14pt; font-weight: bold; color: #888">
				Nota Fiscal Eletrônica
			</td>
		</tr>
		<tr>
			<td>CNPJ: 12.043.236/001-36</td>
			<td style="text-align: center"><%= meses[data.get(Calendar.MONTH)] %>/<%= data.get(Calendar.YEAR) %></td>
		</tr>
	</table>
	<table class="tabela">
		<thead>
			<tr>
				<td style="width: 2cm; text-align: center;">Código</td>
				<td style="width: 10cm;">Nome/Razão Social</td>
				<td>CGC/CPF</td>
				<td>Endereço</td>
				<td>Bairro/Distrito</td>
				<td>Municipio</td>
				<td style="width: 5cm;">Fone/FAX</td>
			</tr>
		</thead>
		
		<tr>
			<td style="text-align: center;"><%= consulta.getPaciente().getIdPaciente() %></td>
			<td><%= consulta.getPaciente().getNome() %></td>
			<td><%= consulta.getPaciente().getCpf() %></td>
			<td></td>
			<td></td>
			<td></td>
			<td><%= consulta.getPaciente().getTelefone() %></td>
		</tr>
	</table>
	
	<table class="tabela tabela_vencimentos" cellpadding="0" cellspacing="0">
		<thead>
			<tr>
				<td style="width: 1cm;">Cód.</td>
				<td>Descrição</td>
				<td style="width: 2.5cm;"></td>
				<td style="width: 4cm;">Valor</td>
				<td style="border-right-width: 0px; width: 4cm">Descontos</td>
			</tr>
		</thead>
		
		<tr>
			<td>101</td>
			<td style="text-align: left;"><%= consulta.getTipoConsulta() %></td>
			<td>
				<% 
				long valor = consulta.getNotaFiscal().getValor().longValue(); 
				long descontos = consulta.getNotaFiscal().getDescontos().longValue();
				
				//long valor = 11;
				//long descontos = 4;
				%>
				
			</td>
			<td>
				<%= valor %>
			</td>
			<td style="border-right-width: 0px; text-align: right;"></td>
		</tr>
		

			<tr>
				<td></td>
				<td style="text-align: left;"></td>
				<td></td>
				<td>
					
				</td>
				<td style="border-right-width: 0px; text-align: right;"></td>
			</tr>
		
			<tr>
				<td></td>
				<td style="text-align: left;"></td>
				<td></td>
				<td></td>
				<td style="border-right-width: 0px; text-align: right;"><%= descontos %></td>
			</tr>

		
		
			<tr>
				<td>&nbsp;</td>
				<td></td>
				<td></td>
				<td></td>
				<td style="border-right-width: 0px;"></td>
			</tr>

		
		<tr>
			<td colspan="3" rowspan="2" style="border-top: 2px solid #000"></td>
			<td style="border-top: 2px solid #000; height: 1cm;">
				<span style="font-family: sans-serif; font-size: 9pt; color: #888">
					Valor Total
				</span><br />
				<%= valor %>
			</td>
			<td style="border-top: 2px solid #000; border-right-width: 0px;">
				<span style="font-family: sans-serif; font-size: 9pt; color: #888">
					Total de Descontos
				</span><br />
				<%= descontos %>
			</td>
		</tr>
		
		<tr>
			<td style="border-top: 2px solid #000; height: 1cm;">
				<span style="font-family: sans-serif; font-size: 9pt; color: #888; text-align: left;">
					Valor Líquido
				</span>
			</td>
			<td style="border-top: 2px solid #000; border-right-width: 0px;">
				<%= valor-descontos %>
			</td>
		</tr>
	</table>
	
	<h>Dados Adicionais</h>
	<table class="tabela assinatura">
		<tr>
			<td colspan="2" style="text-align: center;border-right-width: 0px;">
			<span style="font-family: sans-serif; font-size: 9pt; color: #888; text-align: left;">
					Informações Complementares
		
			</span>
			</td>
						<td colspan="2" style="text-align: center;">
			<span style="font-family: sans-serif; font-size: 9pt; color: #888; text-align: left;">
					Reservado ao Fisco
			</span>
			</td>
		</tr>
		<tr>
		<td style="height: 1cm;"></td>
		<td style="height: 1cm;"></td>
		</tr>
		
	</table>
<%
	} catch (Exception e) {
		e.printStackTrace();
%>
		<p>Colaborador não encontrado.</p>
<%
	}
%>

</body>
</html>